/*
 * Copyright (C) 2012 scchang <scchang@caltech.edu>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package ogame.tester;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import ogame.utilities.Resources;
import ogame.utilities.buildings.Buildings;
import ogame.utilities.datastorage.OgameDataStorage;
import ogame.utilities.defenses.Defenses;
import ogame.utilities.planets.Planets;
import ogame.utilities.research.Research;
import ogame.utilities.ships.Ships;

/**
 *
 * @author scchang <scchang@caltech.edu>
 */
public class Tester {
    
    public static void main(String[] args){
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        System.out.println("Initialzed tester.");
        System.out.println("/////////////////////////////////////////////////");
        System.out.println("Resources: 1");
        System.out.println("Research: 2");
        System.out.println("Buildings: 3");
        System.out.println("Ships: 4");
        System.out.println("Defenses: 5");
        System.out.println("Database: 6");
        System.out.println("All tests: -1.");
        System.out.println("/////////////////////////////////////////////////");
        System.out.println("Enter tests needed to perform.");
        
        try{
            String input = reader.readLine();
            int input_integer = Integer.parseInt(input);
            
            if(input_integer == 1){
                testResources();
            }else if(input_integer == 2){
                testResearch();
            }else if(input_integer == 3){
                testBuildings();
            }else if(input_integer == 4){
                testShips();
            }else if(input_integer == 5){
                testDefenses();
            }else if(input_integer == 6){
                testDatabase();
            }else if(input_integer == -1){
                testResources();
                testResearch();
                testBuildings();
                testShips();
                testDefenses();
                testDatabase();
            }
            
        }catch(IOException e){
            e.printStackTrace();
        }
    }
    
    private static boolean testDatabase(){
        System.out.println("///////////////////////////////////////////////////");
        System.out.println("Testing database.");
        if(OgameDataStorage.unitTest()){
            System.out.println("Database tested sucessfully.");
            System.out.println("///////////////////////////////////////////////////");
            return true;
        }else{
            System.out.println("Database failed testing.");
            System.out.println("///////////////////////////////////////////////////");
            return false;
        }                
    }
    
    private static boolean testDefenses(){
        System.out.println("///////////////////////////////////////////////////");
        System.out.println("Testing defenses.");
        if(Defenses.unitTest()){
            System.out.println("Defenses tested sucessfully.");
            System.out.println("///////////////////////////////////////////////////");
            return true;
        }else{
            System.out.println("Defenses failed testing.");
            System.out.println("///////////////////////////////////////////////////");
            return false;
        }                
    }
    
    private static boolean testShips(){
        System.out.println("///////////////////////////////////////////////////");
        System.out.println("Testing ships.");
        if(Ships.unitTest()){
            System.out.println("Ships tested sucessfully.");
            System.out.println("///////////////////////////////////////////////////");
            return true;
        }else{
            System.out.println("Ships failed testing.");
            System.out.println("///////////////////////////////////////////////////");
            return false;
        }        
    }
    
    private static boolean testBuildings(){
        System.out.println("///////////////////////////////////////////////////");
        System.out.println("Testing buildings.");
        if(Buildings.unitTest()){
            System.out.println("Buildings tested sucessfully.");
            System.out.println("///////////////////////////////////////////////////");
            return true;
        }else{
            System.out.println("Buildings failed testing.");
            System.out.println("///////////////////////////////////////////////////");
            return false;
        }
    }
    
    private static boolean testResearch(){
        System.out.println("///////////////////////////////////////////////////");
        System.out.println("Testing research.");
        if(Research.unitTest()){
            System.out.println("Research tested sucessfully.");
            System.out.println("///////////////////////////////////////////////////");
            return true;
        }else{
            System.out.println("Research failed testing.");
            System.out.println("///////////////////////////////////////////////////");
            return false;
        }
    }
    
    private static boolean testResources(){
        System.out.println("///////////////////////////////////////////////////");
        System.out.println("Testing resources.");
        if(Resources.unitTest()){
            System.out.println("Resources tested sucessfully.");
            System.out.println("///////////////////////////////////////////////////");
            return true;
        }else{
            System.out.println("Resources failed testing.");
            System.out.println("///////////////////////////////////////////////////");
            return false;
        }
    }

}
